In [1]:
# imports
import numpy as np
import pandas as pd
import folium as fm
from folium.plugins import FastMarkerCluster
In [2]:
#csv file clean up, save the infos we need and drop all the rows where the incidents are not well documented
def trimData(file_in,file_out):
    
    data_in = pd.read_csv(file_in,delimiter=',',header=0,nrows=60000,dtype=str)
    
    data_sort = pd.DataFrame(data=data_in,columns=['DATE','TIME','BOROUGH','LATITUDE','LONGITUDE','CONTRIBUTING FACTOR VEHICLE 1','CONTRIBUTING FACTOR VEHICLE 2'])
    
    data_drop_na = data_sort.dropna(subset=['LATITUDE','LONGITUDE'])
    
    date_out = data_drop_na.to_csv(file_out) #cleaned data use for visualization 
In [3]:
trimData('NY_traffic.csv','NY_traffic_cleaned.csv')

working_data = pd.read_csv('NY_traffic_cleaned.csv')

#--------------- map
NYC_location = [40.7128,-74.0060] #direct origin location to NYC

map = fm.Map(location=NYC_location,zoom_start=10.2) # nyc   40.7128° N, -74.0060° W, initialized a map centered nyc

lat=working_data['LATITUDE'].values #obtain latitude  values in dataframe

long=working_data['LONGITUDE'].values #obtain longitude values in dataframe

FastMarkerCluster(data=list(zip(lat,long))).add_to(map) #ziping latitude and longitude into pair

display(map)
In [4]:
print("Hello")
Hello
In [5]:
display(map)